import {observable} from 'mobx';
import {Tools,Bubble} from 'weaver-mobile';
import { RouteLayout,ListPage } from 'weaver-mobile-page';
import * as API from '../../api/home';

const getLabel = Tools.getLabel;

export default class HomeStore {
    /********************************************************/
    @observable loading = false;
    @observable hasRight = '';

    @observable remindList = new ListPage.Store();
    @observable toMoreRoute = new RouteLayout.Store({id:'toMore',route:'/home'})

    //首页顶部
    @observable toplist = {};
    @observable order = [];

    //获取发票类型
    @observable tabList = [];

    //常用功能
    @observable platePart = new ListPage.Store();

    //三方应用
    @observable loadingThree = false;
    @observable threeParties = [];
    @observable threePartiesObj = {};
    @observable remindObj = {};
    @observable pendingObj = {};
    @observable docid = ''; //文档Id
    @observable imagefileid = ''; //附件id

    initData = (value={}) =>{ 
        this.getTopList();
        this.getThreeParties();
        this.getReimbursementReminder();
        this.getUpComing(value);     
    }

    //获取顶部数据
    getTopList = (value={}) =>{
        this.loading = true;
        API.getTopList(value).then( data =>{
            let {toplist,status,errorInfo} = data;
            if(status === '1'){
                this.toplist = toplist;
                this.order = data.order;
            }else{
                Bubble.error(errorInfo)
            }
            
            this.loading = false;
        }) 
    }

    //获取三方数据
    getThreeParties = (value={}) =>{
        this.loadingThree = true;
        API.getThreeParties(value).then( data =>{
            let {threeParties,status,errorInfo} = data;
            if(status === '1'){
                this.threeParties = threeParties;
                this.threePartiesObj = {
                    id:data.id,
                    show:data.show,
                    title:data.title
                };
                this.docid = data.docid
                this.imagefileid = data.imagefileid;
            }else{
                Bubble.error(errorInfo)
            }
            
            this.loadingThree = false;
        }) 

    }

    //获取首页报销提醒
    getReimbursementReminder = (value={}) =>{
        this.loading = true;
        API.getReimbursementReminder(value).then( res =>{
            let {status,remindList,errorInfo} = res;
            if(status === '1'){
                if(remindList){
                    this.remindList.setState(remindList); 
                }else{
                    this.remindList = new ListPage.Store();
                }
                this.remindObj = {
                    id:res.id,
                    show:res.show,
                    title:res.title
                };
                
            }else{
                Bubble.error(errorInfo)
            }
            
            this.loading = false;
        }) 
    }    

    //获取待办事项
    getUpComing = (value={}) =>{
        this.loading = true;
        API.getUpComing(value).then( res =>{
            let {status,upCompingList,errorInfo} = res;
            if(status === '1'){
                if(upCompingList){
                    this.platePart.setState(upCompingList); 
                }else{
                    this.platePart = new ListPage.Store();
                }
                this.pendingObj = {
                    id:res.id,
                    show:res.show,
                    title:res.title
                };
                
            }else{
                Bubble.error(errorInfo)
            }
            
            this.loading = false;
        }) 
    }

    //删除报销提醒
    doDeleteRemind = (value,callBack) =>{
        this.loading = true;
        API.doDeleteReimbursementReminder(value).then( res=>{
            const {status} = res;
            if(status === '1'){
                Bubble.success(getLabel(20461, "删除成功"));
            }else{
                Bubble.error(res.errorInfo)
            }
            callBack && callBack();
            this.loading = false;
        })
    }

    getRoute = (key,currentRoute) =>{
        this.routeData = new RouteLayout.Store({id:key, route:`${currentRoute}`})
    }

    


    
}